package com.moo2u2.android.oaktononthego.locate;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Node;

import android.util.Log;

import com.google.web.bindery.requestfactory.shared.EntityProxyId;
import com.moo2u2.android.oaktononthego.shared.ColleagueProxy;
import com.moo2u2.android.oaktononthego.util.ColleagueManager;

public class Colleague implements ColleagueProxy {

    /**
     * 
     */
    private static final long serialVersionUID = -2053810613220986060L;

    Long id;

    String name;

    String snippet;

    Integer latitude;

    Integer longitude;

    String phone;

    String img;

    @Override
    public EntityProxyId<?> stableId() {
        throw new UnsupportedOperationException();
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getSnippet() {
        return snippet;
    }

    @Override
    public Integer getLongitude() {
        return longitude;
    }

    @Override
    public Integer getLatitude() {
        return latitude;
    }

    @Override
    public String getPhone() {
        return phone;
    }

    @Override
    public String getImg() {
        return img;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void setSnippet(String snippet) {
        this.snippet = snippet;
    }

    @Override
    public void setLongitude(Integer longitude) {
        this.longitude = longitude;
    }

    @Override
    public void setLatitude(Integer latitude) {
        this.latitude = latitude;
    }

    @Override
    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Override
    public void setImg(String img) {
        this.img = img;
    }

    @Override
    public String toString() {
        return "COLLEAGUE - Name: " + name + "; Snippet: " + snippet
                + "; Latitude: " + latitude + "; Longitude: " + longitude
                + "; Phone: " + phone + "; Img: " + img;
    }

    public void populateFromXml(Node node) throws XPathExpressionException {
        XPath xpath2 = XPathFactory.newInstance().newXPath();
        name = (String) xpath2.evaluate("name", node, XPathConstants.STRING);
        snippet = (String) xpath2.evaluate("snippet", node,
                XPathConstants.STRING);
        try {
            latitude = Integer.valueOf((String) xpath2.evaluate("latitude",
                    node, XPathConstants.STRING));
        } catch (NumberFormatException nfe) {
            Log.e(this.getClass().getSimpleName(), "Incorrect latitude", nfe);
            throw nfe;
        }
        try {
            longitude = Integer.valueOf((String) xpath2.evaluate("longitude",
                    node, XPathConstants.STRING));
        } catch (NumberFormatException nfe) {
            Log.e(ColleagueManager.class.getSimpleName(),
                    "Incorrect longitude", nfe);
            throw nfe;
        }
        phone = (String) xpath2.evaluate("phone", node, XPathConstants.STRING);
        img = (String) xpath2.evaluate("img", node, XPathConstants.STRING);
    }

}
